<?php


namespace App\Admin\Extensions;

use App\Models\PurchaseToMaterial;
use Encore\Admin\Grid\Displayers\AbstractDisplayer;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;

class MyStock extends AbstractDisplayer
{
    public function display()
    {
    	//dd(\request()->all());
        $id = $this->getColumn()->getOriginal();
		
        // 审核通过之后才会在材料列表并入 sum
        $number = PurchaseToMaterial::whereHas('purchase',function (Builder $query) {
        	$query->where('status', 2)->where('store_id', 0);
        })
        ->where('material_id', $id)
            ->where('status', 1)
            ->sum('stock');

        return $number;
    }
}
